import Vue from 'vue'

const apiFiles = require.context('./modules', false, /\.js$/)

const api = apiFiles.keys().reduce((modules, modulePath) => {
  const moduleName = modulePath.replace(/^\.\/(.*)\.\w+$/, '$1')
  const value = apiFiles(modulePath)
  modules[moduleName] = value.default
  return modules
}, {})

Vue.prototype.$api = api